package com.sh.sales.happysales.view;


import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.sh.sales.happysales.R;


public class NewToast extends Toast {

    private static Context mContext;
    private NewToast mNewToast;

    private NewToast(Context context) {
        super(context);
        this.mContext = context;
    }

    public NewToast getInstance(Context context) {
        if (mNewToast == null) {
            mNewToast = new NewToast(context);
        }
        return mNewToast;
    }

    public static void makeText(Context context, CharSequence text) {
        if (context == null) {
            return;
        }
        Toast result = new Toast(context);

        //获取LayoutInflater对象  
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //由layout文件创建一个View对象  
        View layout = inflater.inflate(R.layout.newtoast, null);

        //实例化ImageView和TextView对象  
        TextView textView = (TextView) layout.findViewById(R.id.toast_text);

        textView.setText(text);
//        textView.setTextSize(size);
        result.setView(layout);
        result.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        result.setDuration(Toast.LENGTH_SHORT);
        result.show();
    }
}
